<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@page import="com.yy.base.util.UserUtil"%>
<%
if (session.getAttribute(UserUtil.USERSESSION) == null) {
	response.sendRedirect(request.getContextPath());
	return;
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>生产数据采集</title>
	<script src="../../script/mes-import.js"></script>
	<script src="js/manuDataCollection.js"></script>
</head>
<body style="background-color: #393D49;">
<div class="container" id="manuDataCollection">
<article class="row">
<section class="padded bounceInDown">
<form class="layui-form layui-form-pane" lay-filter="myForm">
	<fieldset>
		<div class="row" id="manuBatchDiv">
			<div class="one half">
				<label style="width:130px;" id="sgdLabel">随工单号:</label>
				<input id="code" autoSearch="on" autocomplete="off" placeholder="请扫描随工单编码"/>
				<img src="../../pda/img/scan.png" scanButton onclick="scan('code')"  />
			</div>
			<div class="one half">
				<textarea id="codeInfo" style="height: 65px;background-color: #FAFAFA;border: 0px;" placeholder="随工单信息" readonly="readonly"></textarea>
			</div>
		</div>
		<div class="row" id="vehicleDiv" style="display: none;">
			<div class="one half">
				<label style="width:130px;">载具编号:</label>
				<select id="vehicle" lay-filter="vehicle" lay-search>
					<option value="">--请选择--</option>
				</select>
			</div>
			<div class="one half">
				<textarea id="vehicleInfo" style="height: 65px;background-color: #FAFAFA;border: 0px;" placeholder="工单信息" readonly="readonly"></textarea>
			</div>
		</div>
		<div class="row" id="facInput" style="display: none;">
			<div class="one half">
				<label style="width:130px;">设备编码:</label>
				<input id="facCode" placeholder="请扫描设备编码"/>
				<img src="../../pda/img/scan.png" scanButton onclick="scan('facCode')"  />
			</div>
			<div class="one half">
				<textarea id="facInfo" style="height: 65px;background-color: #FAFAFA;border: 0px;" placeholder="设备信息" readonly="readonly"></textarea>
			</div>
		</div>
		<div class="row" id="testBar" style="display: none;">
			<div class="one half">
				<label style="width:130px;">测棒信息:</label>
				<input id="barLength" placeholder="请录入测棒信息，单位毫米(mm)"/>
			</div>
			<div class="one half">
				<label style="width:130px;">棒上端剩余:</label>
				<input id="barResidue" placeholder="请录入棒上端剩余信息，单位毫米(mm)"/>
			</div>
		</div>
		<div class="row" id="mainProductCodeDiv" style="display: none;">
			<div class="one half">
				<label>
					母锭编码：<span id='oldMainProductCode'></span>
					<input type='hidden' id='newMainProductCode' value=''/>
					&nbsp;&nbsp;<a href='javascript:void(0)' id='modifyMainProductCode'
								   onclick='modifyMainProductCode()' style="color:blue">编辑</a>
					&nbsp;&nbsp;<a href='javascript:void(0)' id='cancelModify' onclick='cancelModify()'
								   style='display: none;color:blue'>取消</a>
				</label>
			</div>
		</div>
		<div class="row">
			<div class="one" style="padding-top: 10px;">
				<textarea id="description" style="height: 60px;" placeholder="此处填写备注信息"></textarea>
			</div>
		</div>
		<!-- 熔化工序显示 坩埚底厚，棒上端剩余 等信息 -->
		<div class="row" id="rhInfo" style="display: none;">
			<div class="one" style="padding-top: 10px;">
				<div id="rhInfoText"></div>
			</div>
		</div>
		<div class="row">
			<div class="padded btn-div" id="manuBatchBtn">
				<button class="turquoise gap-right gap-bottom" type="button" onclick="submitData()">提交</button>
				<button class="turquoise gap-right gap-bottom" type="button" onclick="rework()" v-if="showRework">{{reworkText}}</button>
				<button class="turquoise gap-right gap-bottom" type="button" onclick="addMaterial()" v-if="showAddMatBtn">加料</button>
				&nbsp;&nbsp;&nbsp;
				<button class="turquoise gap-right gap-bottom" type="button" onclick="refresh()">刷新</button>
				<button class="turquoise gap-right gap-bottom" type="button" v-for="btnItem in Dc_Btn_List" v-if="!(btnItem.IS_HIDE_DC_PAGE == 'Y')" onclick="manuDataDc('{{btnItem.EMES_DC_INPUT_DATA_ID}}','{{btnItem.TYPE}}','{{btnItem.OPEN_URL}}')">{{btnItem.NAME}}</button>
			</div>
		</div>
	</fieldset>
</form>
	<fieldset id="dataHistoryPanel" style="margin-top: 5px;min-height: 300px;">
		<div class="tabs ipad">
			<ul role="tablist">
				<li role="tab" v-for="btnItem in Dc_Btn_List"
					v-if="!(btnItem.IS_HIDE_DC_PAGE == 'Y') && btnItem.TYPE == 'DC'"
					aria-controls="#tab{{btnItem.EMES_DC_INPUT_DATA_ID}}" id="li{{btnItem.EMES_DC_INPUT_DATA_ID}}">{{btnItem.NAME}}列表</li>
			</ul>
			<div  v-for="item in hisDataList"  id="tab{{item.PAGEID}}" role="tabpanel">
				<div style="position: absolute;right: 15px;top:-6px;">
					<button class="turquoise gap-right gap-bottom" onclick="saveDCData('{{item.PAGEID}}')">保存</button>
				</div>
				<div id="historyData{{$index}}">
					<table class="responsive" data-max="15">
						<thead>
						<tr>
							<th>序列号</th>
							<th>采集人</th>
							<th>采集时间</th>
							<th v-for="columnItem in item.COLUMN" v-if="!(columnItem.IS_SHOW == 'N')">{{columnItem.NAME}}{{columnItem.CUNAME?'(':''}}{{columnItem.CUNAME}}{{columnItem.CUNAME?')':''}}</th>
							<th>操作</th>
						</tr>
						</thead>
						<tbody>
						<tr v-for="trItem in item.DATA">
							<td>{{$index+1}}</td>
							<td>{{trItem['USERNAME']}}</td>
							<td>{{trItem['CREATED']}}</td>
							<td v-for="tdItem in item.COLUMN" v-if="!(tdItem.IS_SHOW == 'N')">
								<input v-model="trItem[tdItem.SAVE_COLUMN]" id="{{trItem['EMESO_MANU_PROCESS_DATA_ID']}}{{tdItem.CODE}}"/>
							</td>
							<td><a href="javascript:void(0);"
								   onclick="delManuData(\'{{trItem['EMESO_MANU_PROCESS_DATA_ID']}}\')">删除</a></td>
						</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</fieldset>
</section>
</article>
<div id="reworkDialog" style="display: none;">
	<fieldset>
		<div class="row">
			<div class="one">
				<label style="width:130px;">原因：</label>
				<textarea id="reworkReason" style="resize: none;"></textarea>
			</div>
		</div>
	</fieldset>
</div>
</div>
<script>
	var vm = new Vue({
		el:'#manuDataCollection',
		data:{
            hisDataList:[],
            Dc_Btn_List:[],
            showRework: false,
            showAddMatBtn: false,	//显示加料按钮
            reworkText: "返工"		//返工按钮文本
		},
		methods:{
            isEmpty:function(obj){//判断对象是否为空
				if(typeof obj == "undefined" || obj == null || obj == ""){
					return true;
				}else{
					return false;
				}
			}
		},
		watch:{
            hisDataList:{
                handler: function(curVal,oldVal){
                    var _self = this;
                    $.each(curVal,function(index,item){
                        var map = {};
                        var keySet = [];
                        var calFormula = {};
                        $.each(item.COLUMN,function(j,subItem){
                            map[subItem.NAME] = subItem.SAVE_COLUMN;
                            map["前_"+subItem.NAME] = "PRE_"+subItem.SAVE_COLUMN;//此项目前一行的键值对
                            keySet.push(subItem.NAME);
                            if(subItem.FORMULA && subItem.FORMULA !== ""){
                                calFormula[subItem.SAVE_COLUMN] = subItem.FORMULA;
                            }
						});
                        var reg = null;
                        $.each(item.DATA,function(i,v){
                            $.each(calFormula,function(k,fItem){
                                var no_exec = false;//判断是否执行计算公式
                                $.each(keySet,function(x,keyName){
                                    var reg = new RegExp("前_"+keyName , "g");
                                    if(reg.test(fItem)){
                                        fItem = fItem.replace(reg,v[map["前_"+keyName]]);
										no_exec = no_exec || _self.isEmpty(v[map["前_"+keyName]]);
                                    }
                                    reg = new RegExp(keyName , "g");
                                    if(reg.test(fItem)){
                                        fItem = fItem.replace(reg,v[map[keyName]]);
										no_exec = no_exec || _self.isEmpty(v[map[keyName]]);
                                    }
                                });
                                var reg = new RegExp("当前时间" , "g");
                                if(reg.test(fItem)){
                                    fItem = fItem.replace(new RegExp("当前时间" , "g"),v["TIMESTAMP"]);
                                    no_exec = no_exec || _self.isEmpty(v["TIMESTAMP"]);
                                }
                                reg = new RegExp("上一时间" , "g");
                                if(reg.test(fItem)){
                                    fItem = fItem.replace(new RegExp("上一时间" , "g"),v["PRE_TIMESTAMP"]);
                                    no_exec = no_exec || _self.isEmpty(v["PRE_TIMESTAMP"]);
                                }
                                
                                var reg = new RegExp("当前分钟" , "g");
                                if(reg.test(fItem)){
                                    fItem = fItem.replace(new RegExp("当前分钟" , "g"),v["MINU"]);
                                    no_exec = no_exec || _self.isEmpty(v["MINU"]);
                                }
                                reg = new RegExp("上一分钟" , "g");
                                if(reg.test(fItem)){
                                    fItem = fItem.replace(new RegExp("上一分钟" , "g"),v["PRE_MINU"]);
                                    no_exec = no_exec || _self.isEmpty(v["PRE_MINU"]);
                                }
                                if(!no_exec){//为true才执行计算公式
                                    try {
                                        var tmpValue = eval(fItem).toFixed(2);
                                        if(isNaN(tmpValue) || !isFinite(tmpValue)){
                                            v[k] = '';
                                        }else{
                                            v[k] = tmpValue;
                                        }
                                    } catch (e) {
                                    }
                                }
                            });
                        });
                    });
                }
                ,deep:true
			}
		}
	});
</script>
</body>
</html>